#
# Nicholas Yue nicholas_yue@users.sourceforge.net
#
# Note:
# (1) A dummy file include/config.h is required (remance from configure)
# (2) Default installation directory is /usr/local, override with -DCMAKE_INSTALL_PREFIX="" during cmake
#     invocation
# (3) Do the usual "make clean all" to build the library
# (4) To install either "make install" or "make install DESTDIR=<your directory>"
# (5) Need to include changes in include/log4cpp/Portability.hh for OSX to build

INCLUDE_DIRECTORIES ( include )
INCLUDE_DIRECTORIES ( . )

IF (WIN32)
	ADD_DEFINITIONS ( -D_CRT_SECURE_NO_WARNINGS )
ELSE (WIN32)
	IF (APPLE)
		ADD_DEFINITIONS ( -DNDEBUG -DLOG4CPP_HAVE_SSTREAM )
	ELSE (APPLE)
		ADD_DEFINITIONS (-pthread -DNDEBUG -DLOG4CPP_HAVE_SSTREAM )
	ENDIF (APPLE)

	# determine what system supports (equivalent of autotools' "./configure")
	INCLUDE("${CMAKE_CURRENT_SOURCE_DIR}/Configure.cmake")

	CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/include/config-cmake.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/log4cpp/config.h)
	# BEFORE the source dir, so as not to accidentally pick up a configure'd file
	INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_BINARY_DIR}/include)

ENDIF (WIN32)

SET (LOG4CPP_LIBRARY_NAME "log4cppp")

SET (SRC_LOG4CPP
	src/Appender.cpp
	src/AppenderSkeleton.cpp
	src/AppendersFactory.cpp
	src/BufferingAppender.cpp
	src/FactoryParams.cpp
	src/LayoutsFactory.cpp
	src/LevelEvaluator.cpp
	src/Localtime.cpp
	src/PassThroughLayout.cpp
	src/TriggeringEventEvaluatorFactory.cpp
	src/LayoutAppender.cpp
	src/FileAppender.cpp
	src/DailyRollingFileAppender.cpp
	src/RollingFileAppender.cpp
	src/FixedContextCategory.cpp
	src/IdsaAppender.cpp
	src/OstreamAppender.cpp
	src/StringQueueAppender.cpp
	src/SyslogAppender.cpp
	src/RemoteSyslogAppender.cpp
	src/SimpleLayout.cpp
	src/BasicLayout.cpp
	src/PatternLayout.cpp
	src/Category.cpp
	src/CategoryStream.cpp
	src/HierarchyMaintainer.cpp
	src/Configurator.cpp
	src/BasicConfigurator.cpp
	src/SimpleConfigurator.cpp
	src/PropertyConfigurator.cpp
	src/PropertyConfiguratorImpl.cpp
	src/LoggingEvent.cpp
	src/Priority.cpp
	src/NDC.cpp
	src/Filter.cpp
	src/TimeStamp.cpp
	src/StringUtil.cpp
	src/Properties.cpp
	src/Win32DebugAppender.cpp
	src/NTEventLogAppender.cpp
	src/DllMain.cpp
	src/DummyThreads.cpp
	src/MSThreads.cpp
	src/OmniThreads.cpp
	src/PThreads.cpp
	src/PortabilityImpl.cpp
	src/AbortAppender.cpp
	)

#ADD_LIBRARY ( ${LOG4CPP_LIBRARY_NAME} ${SRC_LOG4CPP})
#
#IF (WIN32)
#	TARGET_LINK_LIBRARIES (${LOG4CPP_LIBRARY_NAME} kernel32 user32 ws2_32 advapi32 )
#	SET_TARGET_PROPERTIES(${LOG4CPP_LIBRARY_NAME} PROPERTIES LINK_FLAGS /NODEFAULTLIB:msvcrt )
#ENDIF (WIN32)

SET(mname log4cpp)
SET(mhook t${mname}_hook)
SET(mtest ${mname}_test)
SET(mtarget t${mname})

# defining common source variables
AUX_SOURCE_DIRECTORY(main MODULE_SRC)
AUX_SOURCE_DIRECTORY(hook HOOK_SRC)
AUX_SOURCE_DIRECTORY(test TEST_SRC)
AUX_SOURCE_DIRECTORY(ftest FTEST_SRC)

if (MODULE_SRC)
	ADD_LIBRARY(${mname} ${MODULE_SRC} ${SRC_LOG4CPP})

	if(FTEST_SRC)
		ADD_EXECUTABLE(${mtarget} ${FTEST_SRC})
		TARGET_LINK_LIBRARIES(${mtarget} ${mname} ${OSLIB})
	endif(FTEST_SRC)

	if (TEST_SRC)
		ADD_EXECUTABLE(${mtest} main/ver_log4cpp.c ${TEST_SRC})
		TARGET_LINK_LIBRARIES(${mtest} ${UNITLIB})
	endif(TEST_SRC)

	set(ALLSRCS testConfig 
		testmain testNDC testPattern testPriority 
		testDailyRollingFileAppender
		testPropertyConfig)

	if (WIN32)
		list(APPEND ALLSRCS testNTEventLog)		
	endif(WIN32)

	foreach (exe ${ALLSRCS})
		message(STATUS "    subprog: " ${src} " " ${exe} )
		add_executable(${exe} tests/${exe}.cpp)
		TARGET_LINK_LIBRARIES(${exe} ${mname} ${OSLIB})
	endforeach()
endif(MODULE_SRC)

SET_PMOD()
